package com.java.day08.homework.pk;

import java.util.Random;
import java.util.Scanner;

/**
 * 决斗类
 */
public class Duel {

    //创建英雄
    public static Hero createHero() {
        Hero hero = new Hero();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入英雄姓名:");
        String name = scanner.next();
        hero.setName(name);

        Random random = new Random();
        //生命随机 1200~1500
        hero.setLife(1200 + random.nextInt(500 + 1 - 200));
        //伤害随机 100~150
        hero.setAttack(100 + random.nextInt(50 + 1));
        //打印英雄面板
        System.out.println("英雄面板:" + hero);
        return hero;
    }

    //决斗
    public static void battle(Fightable play1, Fightable play2) {
        //回合数
        int count = 1;
        System.out.println("开始决斗:");
        while (true) {
            System.out.println();
            if (play1.isAlive() && play2.isAlive()) {
                System.out.println("第" + (count++) + "回合");
                //谁先手
                Random random = new Random();
                int i = random.nextInt(2);
                if (i == 0) {
                    //play1先手
                    System.out.println("玩家1先手");
                    play1.fight(play2);
                    if (play2.isAlive()) {
                        play2.fight(play1);
                    }
                }
                if (i == 1) {
                    //play2先手
                    System.out.println("玩家2先手");
                    play2.fight(play1);
                    if (play1.isAlive()) {
                        play1.fight(play2);
                    }
                }
                System.out.println(play1);
                System.out.println(play2);
            } else {
                if (play1.isAlive()) {
                    System.out.println("玩家1获胜");
                    return;
                }
                System.out.println("玩家2获胜");
                return;
            }
        }
    }
}
